package ru.cod.rs.managers;

import java.util.ArrayList;
import java.util.List;

import ru.cod.rs.enums.Buildings;
import ru.cod.rs.enums.Sides;
import ru.cod.rs.objects.SideObject;
import ru.cod.rs.views.GameView;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

/**
 * Manager
 * 
 * @author Suslov Vadim
 * 
 */
public class GameManager extends DrawManager {

	private List<SideObject> buildings;

	public GameManager(Context c, GameView v) {
		super(c, v);
		buildings = new ArrayList<SideObject>();
		pushBuilding(Buildings.EXAMPLE, Sides.ALLY);
		pushBuilding(Buildings.EXAMPLE, Sides.ENEMY);
	}

	// //////////////////////////////////////

	// ///////////////////////////////////////
	@Override
	protected void update() {
	};

	@Override
	protected void render(Canvas c) {
		c.drawColor(Color.GRAY);
		drawText(c);
		drawBuildings(c);

	}

	// /////////////////////////////////////////////

	private void drawText(Canvas canvas) {
		Paint p = new Paint();
		p.setColor(Color.GREEN);
		canvas.drawText(String.valueOf(view.getWidth()), view.getWidth() - 25,
				15, p);
	}

	private void drawBuildings(Canvas canvas) {
		if (!buildings.isEmpty()) {
			for (SideObject building : buildings) {
				building.draw(canvas);
			}
		}
	}

	// /////////////////////////////////////////////

	private void pushBuilding(Buildings b, Sides s) {
		SideObject building = new SideObject();
		Bitmap bitmap = getImage(b.bitmapId());

		building.setImage(bitmap);

		int x = 0, y = view.getHeight() - building.getHeight();

		if (Sides.ENEMY.equals(s)) {
			x = view.getWidth() - building.getWidth();
		}
		building.setSide(s);
		building.setX(x);
		building.setY(y);
		buildings.add(building);
	}

}
